package com.bw.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bw.seriver.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author 31629
 * @date 2025年09月01日 14:36
 */
@RestController
public class OrderInfoController {
   @Autowired
    private OrderInfoService orderInfoService;
   @RequestMapping("s1")
   public JSONObject select1(){
       JSONObject result = new JSONObject();
       result.put("status",0);
       result.put("msg","");
       JSONArray data = new JSONArray();
       result.put("data",data);

       List<Map<String, Object>> maps = orderInfoService.select1();
       Map<String, Object> map = maps.get(0);

       JSONObject col1 = new JSONObject();
       col1.put("name","当日完成运输次数");
       col1.put("value",map.get("cta"));

       JSONObject col2 = new JSONObject();
       col2.put("name","当日完成运输里程");
       col2.put("value",map.get("ctb"));

       JSONObject col3 = new JSONObject();
       col3.put("name","当日完成运输时长");
       col3.put("value",map.get("ctc"));

       data.add(col1);
       data.add(col2);
       data.add(col3);
       return  result;
   }
   @RequestMapping("s2")
    public JSONObject select2(){
       JSONObject rest = new JSONObject();
       rest.put("status",0);
       rest.put("msg","");
       List<Map<String, Object>> maps = orderInfoService.select2();
       for (Map<String, Object> map : maps) {
           rest.put("data",map.get("cta"));
       }
       return rest;
   }
   @RequestMapping("s3")
    public JSONObject select3(){
       JSONObject rest = new JSONObject();
       rest.put("status",0);
       rest.put("msg","");
       JSONObject data = new JSONObject();
       rest.put("data",data);

       JSONArray columns = new JSONArray();
       JSONArray rows = new JSONArray();

       data.put("columns",columns);
       data.put("rows",rows);

       JSONObject col1 = new JSONObject();
       col1.put("name","机构");
       col1.put("id","name");

       JSONObject col2 = new JSONObject();
       col2.put("name","完运时长");
       col2.put("id","cta");

       columns.add(col1);
       columns.add(col2);

       List<Map<String, Object>> maps = orderInfoService.select3();
       for (Map<String, Object> map : maps) {
           JSONObject row = new JSONObject();
           row.put("name",map.get("name"));
           row.put("cta",map.get("cta"));
           rows.add(row);
       }


       return rest;
   }
   @RequestMapping("s4")
    public JSONObject select4(){
       JSONObject rest = new JSONObject();
       rest.put("status",0);
       rest.put("msg","");
       JSONObject data = new JSONObject();


       JSONArray categories = new JSONArray();
       JSONArray series = new JSONArray();

       data.put("categories",categories);
       data.put("series",series);

       JSONObject series_row = new JSONObject();
       series_row.put("name","配送成功数");
       series.add(series_row);

       JSONArray row = new JSONArray();
       series_row.put("data",row);

       List<Map<String, Object>> maps = orderInfoService.select4();
       for (Map<String, Object> map : maps) {
           categories.add(map.get("org_name"));
           row.add(map.get("cta"));
       }
       rest.put("data",data);
       return rest;
   }
   @RequestMapping("s5")
    public JSONObject select5(){
       JSONObject rest = new JSONObject();
       rest.put("status",0);
       rest.put("msg","");
       JSONArray data = new JSONArray();
       rest.put("data",data);

       List<Map<String, Object>> maps = orderInfoService.select5();
       Map<String, Object> map = maps.get(0);
       JSONObject row = new JSONObject();
       row.put("name","按单总数");
       row.put("value",map.get("cta"));

       JSONObject row1 = new JSONObject();
       row1.put("name","发单总数");
       row1.put("value",map.get("sm"));

       JSONObject row2 = new JSONObject();
       row2.put("name","完成运动数");
       row2.put("value",map.get("ctc"));

       data.add(row);
       data.add(row1);
       data.add(row2);

       return rest;
   }
    @RequestMapping("s6")
    public JSONObject select6(){
        JSONObject rest = new JSONObject();
        rest.put("status",0);
        rest.put("msg","");
        JSONArray data = new JSONArray();
        rest.put("data",data);

        List<Map<String, Object>> maps = orderInfoService.select6();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("name",map.get("name"));
            row.put("value",map.get("c"));
            data.add(row);
        }
        return rest;
    }
    @RequestMapping("s7")
    public JSONObject select7(){
        JSONObject rest = new JSONObject();
        rest.put("status",0);
        rest.put("msg","");
        JSONObject data = new JSONObject();
        rest.put("data",data);

        JSONArray categories = new JSONArray();
        JSONArray series = new JSONArray();

        data.put("categories",categories);
        data.put("series",series);

        JSONObject series_row = new JSONObject();
        series_row.put("name","沈阳");
        series.add(series_row);

        JSONArray row = new JSONArray();
        series_row.put("data",row);

        List<Map<String, Object>> maps = orderInfoService.select7();
        for (Map<String, Object> map : maps) {
            categories.add(map.get("name"));
            row.add(map.get("cta"));
        }
        return rest;
    }
    @RequestMapping("s8")
    public JSONObject select8(){
        JSONObject rest = new JSONObject();
        rest.put("status",0);
        rest.put("msg","");
        JSONObject data = new JSONObject();
        rest.put("data",data);

        JSONArray columns = new JSONArray();
        JSONArray rows = new JSONArray();

        data.put("columns",columns);
        data.put("rows",rows);

        JSONObject col1 = new JSONObject();
        col1.put("name","id序号");
        col1.put("id","id");

        JSONObject col2 = new JSONObject();
        col2.put("name","地区");
        col2.put("id","name");

        JSONObject col3 = new JSONObject();
        col3.put("name","运输里程");
        col3.put("id","cta");

        columns.add(col1);
        columns.add(col2);
        columns.add(col3);

        List<Map<String, Object>> maps = orderInfoService.select8();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("id",map.get("id"));
            row.put("name",map.get("name"));
            row.put("cta",map.get("cta"));
            rows.add(row);
        }
        return rest;
    }
    @RequestMapping("s9")
    public JSONObject select9(){
        JSONObject rest = new JSONObject();
        rest.put("status",0);
        rest.put("msg","");
        List<Map<String, Object>> maps = orderInfoService.select9();
        for (Map<String, Object> map : maps) {
            rest.put("data",map.get("sm"));
        }
        return rest;
    }
    @RequestMapping("s10")
    public JSONObject select10(){
        JSONObject rest = new JSONObject();
        rest.put("status",0);
        rest.put("msg","");
        JSONArray data = new JSONArray();
        rest.put("data",data);


        List<Map<String, Object>> maps = orderInfoService.select10();
        for (Map<String, Object> map : maps) {
            JSONObject rows = new JSONObject();
            rows.put("name",map.get("name"));
            rows.put("value",map.get("sm"));
            data.add(rows);
        }
        return rest;
    }
    @RequestMapping("s11")
    public JSONObject select11(){
        JSONObject rest = new JSONObject();
        rest.put("status",0);
        rest.put("msg","");
        JSONObject data = new JSONObject();
        rest.put("data",data);
        JSONArray columns = new JSONArray();
        JSONArray rows = new JSONArray();

        data.put("columns",columns);
        data.put("rows",rows);

        JSONObject col1 = new JSONObject();
        col1.put("name","序号");
        col1.put("id","id");

        JSONObject col2 = new JSONObject();
        col2.put("name","机构");
        col2.put("id","name");

        JSONObject col3 = new JSONObject();
        col3.put("name","运输数量");
        col3.put("id","c");

        JSONObject col4 = new JSONObject();
        col4.put("name","运输完成排名");
        col4.put("id","pm");

        columns.add(col1);
        columns.add(col2);
        columns.add(col3);
        columns.add(col4);

        List<Map<String, Object>> maps = orderInfoService.select11();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("id",map.get("id"));
            row.put("name",map.get("name"));
            row.put("c",map.get("c"));
            row.put("pm",map.get("pm"));
            rows.add(row);
        }
        return rest;
    }
    @RequestMapping("s12")
    public JSONObject select12(){
        JSONObject rest = new JSONObject();
        rest.put("status",0);
        rest.put("msg","");
        JSONObject data = new JSONObject();
        rest.put("data",data);

        JSONArray mapData = new JSONArray();
        JSONArray tooltipNames = new JSONArray();
        JSONArray tooltipUnits = new JSONArray();

        List<Map<String, Object>> maps = orderInfoService.select12();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("name",map.get("name"));
            row.put("value",map.get("id"));

            mapData.add(row);
            JSONArray tooltipValues = new JSONArray();
            tooltipValues.add(map.get("c"));
            tooltipValues.add(map.get("ctb"));
            row.put("tooltipValues",tooltipValues);
        }

        data.put("mapData",mapData);
        data.put("valueName","人口");
        data.put("tooltipNames",tooltipNames);
        tooltipNames.add("运单数量");
        tooltipUnits.add("运单金额");
        data.put("tooltipUnits",tooltipUnits);

        tooltipUnits.add("元");

        return rest;
    }
}
